package com.sg.service.impl;

import com.github.pagehelper.PageHelper;
import com.sg.bean.Clothing;
import com.sg.dao.ClothingDao;
import com.sg.service.ClothingService;
import com.sg.vo.ChartInfo;
import com.sg.vo.ClothingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zh
 * 衣物物品业务逻辑实现类
 */
@Service
public class ClothingServiceImpl implements ClothingService {
    @Autowired
    ClothingDao clothingDao;
    @Override
    public List<ClothingVO> findAll() {
        return clothingDao.findAll();
    }

    @Override
    public List<ClothingVO> findByName(String uName) {
        return clothingDao.findByName(uName);
    }

    @Override
    public Clothing fingById(int clothingId) {
        return clothingDao.fingById(clothingId);
    }

    @Override
    public boolean add(Clothing clothing) {
        return clothingDao.add(clothing)>0?true:false;
    }

    @Override
    public boolean update(Clothing clothing) {
        return clothingDao.update(clothing)>0?true:false;
    }

    @Override
    public boolean delete(int[] array) {
        return clothingDao.delete(array)>0?true:false;
    }

    @Override
    public List<ClothingVO> findByStateName(String clothingStateName) {
        return clothingDao.findByStateName(clothingStateName);
    }

    @Override
    public List<ClothingVO> findAllPage(int pageNum, int pageSize) {
        //开启分页，pageNum页码pageSize
        PageHelper.startPage(pageNum,pageSize);
        return clothingDao.findAll();
    }

    @Override
    public List<ChartInfo> findStatPie() {
        return clothingDao.findStat();
    }

    @Override
    public Map<String, List> findStatBar() {
        Map<String, List> map = new HashMap<>();
        List<ChartInfo> list = clothingDao.findStat();
        List<String> names = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (ChartInfo info : list){
            names.add(info.getName());
            values.add(info.getValue());
        }
        map.put("names",names);
        map.put("values",values);
        return map;
    }
}
